/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.subject.bank.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.subject.bank.entity.TsubjectBank;
import com.jeesite.modules.zx.subject.bank.service.TsubjectBankService;

/**
 * 题库题目Controller
 * @author zpp
 * @version 2020-03-27
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/subject/bank/tsubjectBank")
public class TsubjectBankController extends BaseController {

	@Autowired
	private TsubjectBankService tsubjectBankService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TsubjectBank get(String id, boolean isNewRecord) {
		return tsubjectBankService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:view")
	@RequestMapping(value = {"list", ""})
	public String list(TsubjectBank tsubjectBank, Model model) {
		model.addAttribute("tsubjectBank", tsubjectBank);
		return "modules/zx/subject/bank/tsubjectBankList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TsubjectBank> listData(TsubjectBank tsubjectBank, HttpServletRequest request, HttpServletResponse response) {
		tsubjectBank.setPage(new Page<>(request, response));
		Page<TsubjectBank> page = tsubjectBankService.findPage(tsubjectBank);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:view")
	@RequestMapping(value = "form")
	public String form(TsubjectBank tsubjectBank, Model model) {
		model.addAttribute("tsubjectBank", tsubjectBank);
		return "modules/zx/subject/bank/tsubjectBankForm";
	}

	/**
	 * 保存题库题目
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TsubjectBank tsubjectBank) {
		tsubjectBankService.save(tsubjectBank);
		return renderResult(Global.TRUE, text("保存题库题目成功！"));
	}
	
	/**
	 * 停用题库题目
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TsubjectBank tsubjectBank) {
		tsubjectBank.setStatus(TsubjectBank.STATUS_DISABLE);
		tsubjectBankService.updateStatus(tsubjectBank);
		return renderResult(Global.TRUE, text("停用题库题目成功"));
	}
	
	/**
	 * 启用题库题目
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TsubjectBank tsubjectBank) {
		tsubjectBank.setStatus(TsubjectBank.STATUS_NORMAL);
		tsubjectBankService.updateStatus(tsubjectBank);
		return renderResult(Global.TRUE, text("启用题库题目成功"));
	}
	
	/**
	 * 删除题库题目
	 */
	@RequiresPermissions("zx:subject:bank:tsubjectBank:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TsubjectBank tsubjectBank) {
		tsubjectBankService.delete(tsubjectBank);
		return renderResult(Global.TRUE, text("删除题库题目成功！"));
	}
	
}